#!/usr/bin/python
import os
import sys
import commands

input='lailin.txt'
fin=open(input, 'r')

output='mcinfo.txt'
fout=open(output, 'w')

### check AMI 
dict_mcinfo=dict()
for lines in fin.readlines():
  if lines[-1]=='\n': line=lines[:-1]
  else: line=lines
  if len(line)==0: continue
  mcid=line.split('.')[1]
  dataset=line.split('/')[0]
  if not mcid in dict_mcinfo.keys(): dict_mcinfo[mcid]={}
  dict_mcinfo[mcid][dataset]={}
  ## look up AMI
  cmd='ami dataset info '+dataset+" | grep totalEvents | awk '{print $2}' "
  totEvents=commands.getoutput(cmd)
  dict_mcinfo[mcid][dataset]['totEvents']=float(totEvents)
  fout.write('%-10s%s  %s\n' % (mcid, dataset, totEvents))
  print dataset
